package org.example.sportdemo.controller;

import org.example.sportdemo.entity.Competition;
import org.example.sportdemo.entity.Ground;
import org.example.sportdemo.service.CompetitionService;
import org.example.sportdemo.service.GroundService;
import org.example.sportdemo.utils.PageUtils;
import org.example.sportdemo.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/ground")
public class GroundController {

    @Autowired
    private GroundService groundService;

    //分页
    @RequestMapping("/page")
    public R page(@RequestParam Map<String, Object> params){

        PageUtils page = groundService.queryPage(params);

        R r = new R();
        r.put("page",page);
        return r;
    }

    //新增
    @RequestMapping(value = "/addGround")
    public R addCompetition(@RequestBody Ground ground){
        System.out.println(ground);
        groundService.addGround(ground);
        return R.ok().put("ground",ground);
    }

    //修改
    @RequestMapping(value = "/updateGround")
    public R updateGround(@RequestBody Ground ground){
        System.out.println(ground);
        groundService.updateGround(ground);
        return R.ok().put("ground",ground);
    }


    //根据id查询
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
        Ground ground = groundService.selectById(id);
        return R.ok().put("ground",ground);
    }

    //删除
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
        groundService.deleteByIds(ids);
        return R.ok();
    }

    //selectForHot
    @RequestMapping("/selectForHot")
    public R selectForHot(){
        List<Ground> groundList = groundService.selectForHot();
        return R.ok().put("list",groundList);
    }
}
